package classroom;

import java.util.Arrays;

/**
 * @author yicixingchen
 * @version 1.0
 * Create by 2022/10/25 10:40
 */

public class main {
    public static void main(String[] args) {
        insertionSort insertionSort = new insertionSort();
        int[] a = {2,8,4,5,1};
        insertionSort.sort(a);
        System.out.println(Arrays.toString(a));
    }

}

abstract class baseSort{
    public abstract void sort(int[] a);
}

class insertionSort extends baseSort{
    @Override
    public void sort(int[] a) {
        int v,j;
        for (int i = 1; i < a.length; i++) {
            v = a[i];
            j = i - 1;
            while (j >= 0 && a[j] > v){
                a[j + 1] = a[j];
                j--;
            }
            a[j+ 1] = v;
        }
    }
}
